﻿@{
    ViewBag.Title = "PayManage";
    Layout = "~/Views/Shared/Template.cshtml";
}

@using Partner.MVC.Models;
@{
    var user = Session["LoginUser"] as User_Info;
}
<script src="~/Content/jquery.min.js"></script>

<div style="height: 300px;width: 100%;background:url(/static/hbweb/images/me.jpg);">
    <div class="container">
        <div class="header-message">
            <img class="fl" src="http://pic.huobanchina.com/o_1bp7omfg8e821pc4bbg1u8g1ifl9.jpeg" alt="" />
            <div class="fl header-text">
                <h3 class="user-name">@user.Use_Name </h3>
                <i class="icon-fabu3 point user-namei"></i>
            </div>
            <a id="AlterPwd" style="width:85px;" data-toggle="modal" data-target="#myModal" class="fr fn-font-hover-blue change change-password">
                修改密码
            </a>
        </div>
    </div>
</div>

<style>
    table {
        margin: 30px 20px;
    }

    tr {
        height: 40px;
    }

    select {
        width: 200px;
        height: 35px;
    }
</style>

<div class="bgcSil">
    <div class="container">
        <div class="mt30" style="width: 100%">
            <ul id="divLeft" style="width:24%" class="nav navbar-nav"></ul>
            <div id="divContent" style="width:75%;" class="fr mb80 cont bgcWhit news-list-con">
                @foreach (var a in Model)
                {
                    <table border="1">
                        <tr style=" background:blue; color:white; font-weight:bolder;">
                            <td style="width:150px;">@a.B_BankName</td>
                            <td></td>
                            <td> 尾号： @a.B_BankAccount  </td>
                        </tr>
                        <tr>
                            <td> 快捷支付 @(a.B_FastPay == 1 ? "已开通" : "未开通")</td>
                            <td></td>
                            <td align="right"><a href="#" onclick="delCard(@a.B_Id)" style="color:#808080; font-size:12px;">删除</a></td>
                        </tr>
                    </table>
                }
                <table id="addCard1" data-toggle="modal" data-target="#addCard" class="login-link fn-font-clor-black" border="1" style=" color:blue;font-weight:bolder; width:365px; height:80px;">
                    <tr>
                        <td align="center">添加银行卡</td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>

<!-- 添加银行卡 -->
<div class="modal fade" id="addCard" data-backdrop="false" data-keyboard="false" tabindex="-1" role="dialog" aria-labelledby="myModalLable" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" style="color:blue;">添加银行卡</h4>
            </div>
            <div class="modal-body">
                <table>
                    <tr>
                        <td>
                            <div style="padding: 20px 150px 10px;">
                                <div class="row">
                                    <div class="col-lg-3">
                                        <div class="input-group">
                                            <span class="input-group-btn">
                                                <button class="btn btn-default" type="button" disabled>
                                                    真实姓名：
                                                </button>
                                            </span>
                                            <input style="width:200px;" value="@ViewBag.Name" disabled type="text" class="form-control" id="txtName">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div style="padding: 20px 150px 10px;">
                                <div class="row">
                                    <div class="col-lg-3">
                                        <div class="input-group">
                                            <span class="input-group-btn">
                                                <button class="btn btn-default" type="button" disabled>
                                                    开卡银行：
                                                </button>
                                            </span>
                                            <select id="bankName">
                                                <option value="中国银行">请选择银行...</option>
                                                <option value="中国银行">中国银行</option>
                                                <option value="中国工商银行">中国工商银行</option>
                                                <option value="邮政储蓄银行">邮政储蓄银行</option>
                                                <option value="中国建设银行">中国建设银行</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div style="padding: 20px 150px 10px;">
                                <div class="row">
                                    <div class="col-lg-3">
                                        <div class="input-group">
                                            <span class="input-group-btn">
                                                <button class="btn btn-default" type="button" disabled>
                                                    银行卡号：
                                                </button>
                                            </span>
                                            <input style="width:200px;" type="text" class="form-control" id="bankCard">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div style="padding: 20px 150px 10px;">
                                <div class="row">
                                    <div class="col-lg-3">
                                        <div class="input-group">
                                            <span class="input-group-btn">
                                                <button class="btn btn-default" type="button" disabled>
                                                    账户类型：
                                                </button>
                                            </span>
                                            <select id="type">
                                                <option value="1">储蓄卡</option>
                                                <option value="2">信用卡</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="addCardbank()">绑定</button>
            </div>
        </div>
    </div>
</div>

<script>
    // 绑定银行卡
    function addCardbank() {
        var bankName = $("#bankName").val();
        var realName = $("#txtName").val();
        var bankCard = $("#bankCard").val();
        var type = $("#type").val();
        var bankCardReg=/\d{15}|\d{19}/
        if(!bankCardReg.test(bankCard))
        {
            alert('卡号不符合格式,请检查')
        }
        else
        {
            $.ajax({
                type: "post",
                url: "/UserCenter/addCard",
                data: { bankName: bankName, realName: realName, bankCard: bankCard, type: type },
                success: function (result) {
                    if (result >0) {
                        alert('添加成功')
                        location.href = "/UserCenter/PayManage";
                    }
                    else if(result==0)
                    {
                        alert('用户已存在')
                    }
                    else
                    {
                    alert('添加失败')
                    }
                }
            })
        }

    }
    // 删除银行卡
    function delCard(id) {
        if(confirm('确定要解除绑定吗？'))
        {
            $.ajax({
                type: "post",
                url: "/UserCenter/delCard",
                data: { id: id },
                success: function (result) {
                    if (result == 1) {
                        alert("解除绑定成功!");
                        location.href = "/UserCenter/PayManage";
                        return;
                    }
                    alert("解除绑定失败!");
                }
            })
        }

    }
</script>

<script>
    ParentNav();
    // 绑定根节点
    function ParentNav() {
        $.ajax({
            type: "post",
            url: "/Partner/LeftNav",
            dataType: "json",
            success: function (data) {
                var htmltab = "";
                for (var i = 0; i < data.length; i++) {
                    htmltab += "<li class=\"dropdown\"><a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\" style=\"width: 175px;font-size: 16px;\">" + data[i].Lar_Name + "</a>" + SonNav(data[i].Limit_Id) + "</li>";
                }
                $("#divLeft").append(htmltab);
            },
            error: function (err) {
                alert(err);
            }
        })
    }
    // 绑定子节点
    function SonNav(id) {
        var html1 = "";
        $.ajax({
            type: "post",
            url: "/Partner/LeftSon",
            data: { pid: id },
            dataType: "json",
            async: false,
            success: function (data) {
                var strhtml = "<ul class=\"dropdown-menu\">"
                for (var i = 0; i < data.length; i++) {
                    strhtml += "<li><a href=\"" + data[i].Limit_Url + "\">" + data[i].Limit_Name + "</a></li>"
                }
                strhtml += "</ul>";
                html1 = strhtml;
            }
        })
        return html1;
    }
</script>